package com.et.u1.util.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.et.u1.R;


public class HeartLayout extends RelativeLayout {
    private AbstractPathAnimator mAnimator;

    public HeartLayout(Context context) {
        super(context);
        this.init((AttributeSet) null, 0);
    }

    public HeartLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.init(attrs, 0);
    }

    public HeartLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init(attrs, defStyleAttr);
    }

    private void init(AttributeSet attrs, int defStyleAttr) {
        TypedArray a = this.getContext().obtainStyledAttributes(attrs, R.styleable.HeartLayout, defStyleAttr, 0);
        this.mAnimator = new PathAnimator(AbstractPathAnimator.Config.fromTypeArray(a));
        a.recycle();
    }

    public AbstractPathAnimator getAnimator() {
        return this.mAnimator;
    }

    public void setAnimator(AbstractPathAnimator animator) {
        this.clearAnimation();
        this.mAnimator = animator;
    }

    public void clearAnimation() {
        for (int i = 0; i < this.getChildCount(); ++i) {
            this.getChildAt(i).clearAnimation();
        }

        this.removeAllViews();
    }

    public void addHeart(int res) {
        HeartView heartView = new HeartView(this.getContext(), res);
        this.mAnimator.start(heartView, this);
    }

}